//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "RatchetMaxPayoff.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/Instruments/DoubleStickyRatchetPayoff.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CRatchetMaxPayoff::CRatchetMaxPayoff (Double gearing1, Double gearing2, Double gearing3, Double spread1, Double spread2, Double spread3, Double initialValue1, Double initialValue2, Double accrualFactor) : CDoubleStickyRatchetPayoff(CRatchetMaxPayoff::typeid)
{
    try
    {
#ifdef HANDLE
        _phRatchetMaxPayoff = NULL;
#endif
        QuantLib::Real _gearing1 = (QuantLib::Real)ValueHelper::Convert (gearing1);
        QuantLib::Real _gearing2 = (QuantLib::Real)ValueHelper::Convert (gearing2);
        QuantLib::Real _gearing3 = (QuantLib::Real)ValueHelper::Convert (gearing3);
        QuantLib::Real _spread1 = (QuantLib::Real)ValueHelper::Convert (spread1);
        QuantLib::Real _spread2 = (QuantLib::Real)ValueHelper::Convert (spread2);
        QuantLib::Real _spread3 = (QuantLib::Real)ValueHelper::Convert (spread3);
        QuantLib::Real _initialValue1 = (QuantLib::Real)ValueHelper::Convert (initialValue1);
        QuantLib::Real _initialValue2 = (QuantLib::Real)ValueHelper::Convert (initialValue2);
        QuantLib::Real _accrualFactor = (QuantLib::Real)ValueHelper::Convert (accrualFactor);
        _ppRatchetMaxPayoff = new boost::shared_ptr<QuantLib::RatchetMaxPayoff> (new QuantLib::RatchetMaxPayoff ( _gearing1,  _gearing2,  _gearing3,  _spread1,  _spread2,  _spread3,  _initialValue1,  _initialValue2,  _accrualFactor ));
        SetDoubleStickyRatchetPayoff (boost::dynamic_pointer_cast<QuantLib::DoubleStickyRatchetPayoff> (*_ppRatchetMaxPayoff));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::CRatchetMaxPayoff::CRatchetMaxPayoff (boost::shared_ptr<QuantLib::RatchetMaxPayoff>& childNative, Object^ owner) : CDoubleStickyRatchetPayoff(CRatchetMaxPayoff::typeid)
{
#ifdef HANDLE
	_phRatchetMaxPayoff = NULL;
#endif
	_ppRatchetMaxPayoff = &childNative;
    _ppDoubleStickyRatchetPayoff = new boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff> (boost::dynamic_pointer_cast<QuantLib::DoubleStickyRatchetPayoff> (*_ppRatchetMaxPayoff));
}
Cephei::QL::Instruments::CRatchetMaxPayoff::CRatchetMaxPayoff (QuantLib::RatchetMaxPayoff& childNative, Object^ owner) : CDoubleStickyRatchetPayoff(CRatchetMaxPayoff::typeid)
{
#ifdef HANDLE
	_phRatchetMaxPayoff = NULL;
#endif
	_ppRatchetMaxPayoff = new boost::shared_ptr<QuantLib::RatchetMaxPayoff> (&childNative);
    _ppDoubleStickyRatchetPayoff = new boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff> (boost::dynamic_pointer_cast<QuantLib::DoubleStickyRatchetPayoff> (*_ppRatchetMaxPayoff));
    _RatchetMaxPayoffOwner = owner;
    _DoubleStickyRatchetPayoffOwner = owner;
}

Cephei::QL::Instruments::CRatchetMaxPayoff::CRatchetMaxPayoff (CRatchetMaxPayoff^ copy) : CDoubleStickyRatchetPayoff(CRatchetMaxPayoff::typeid)
{
#ifdef HANDLE
	_phRatchetMaxPayoff = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppRatchetMaxPayoff = new boost::shared_ptr<QuantLib::RatchetMaxPayoff> (copy->GetShared());
        _ppDoubleStickyRatchetPayoff = new boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff> (boost::dynamic_pointer_cast<QuantLib::DoubleStickyRatchetPayoff> (*_ppRatchetMaxPayoff));
    }
}
Cephei::QL::Instruments::CRatchetMaxPayoff::CRatchetMaxPayoff (System::Type^ t) : CDoubleStickyRatchetPayoff(CRatchetMaxPayoff::typeid)
{
#ifdef HANDLE
	_phRatchetMaxPayoff = NULL;
#endif
	if (!t->IsSubclassOf(CRatchetMaxPayoff::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CRatchetMaxPayoff::CRatchetMaxPayoff (QuantLib::Handle<QuantLib::RatchetMaxPayoff>& childNative, Object^ owner)  : CDoubleStickyRatchetPayoff(CRatchetMaxPayoff::typeid)
{
	_phRatchetMaxPayoff = &childNative;
	_ppRatchetMaxPayoff = &static_cast<boost::shared_ptr<QuantLib::RatchetMaxPayoff>>(childNative.currentLink());
    _ppDoubleStickyRatchetPayoff = new boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff> (boost::dynamic_pointer_cast<QuantLib::DoubleStickyRatchetPayoff> (*_ppRatchetMaxPayoff));
    _RatchetMaxPayoffOwner = owner;
}
Cephei::QL::Instruments::CRatchetMaxPayoff::CRatchetMaxPayoff (QuantLib::Handle<QuantLib::RatchetMaxPayoff> childNative)  : CDoubleStickyRatchetPayoff(CRatchetMaxPayoff::typeid)
{
	_phRatchetMaxPayoff = &childNative;
	_ppRatchetMaxPayoff = &static_cast<boost::shared_ptr<QuantLib::RatchetMaxPayoff>>(childNative.currentLink());
    _ppDoubleStickyRatchetPayoff = new boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff> (boost::dynamic_pointer_cast<QuantLib::DoubleStickyRatchetPayoff> (*_ppRatchetMaxPayoff));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CRatchetMaxPayoff::CRatchetMaxPayoff (QuantLib::RatchetMaxPayoff childNative)  : CDoubleStickyRatchetPayoff(CRatchetMaxPayoff::typeid)
{
#ifdef HANDLE
	_phRatchetMaxPayoff = NULL;
#endif
	_ppRatchetMaxPayoff = new boost::shared_ptr<QuantLib::RatchetMaxPayoff> (new QuantLib::RatchetMaxPayoff (childNative));
    _ppDoubleStickyRatchetPayoff = new boost::shared_ptr<QuantLib::DoubleStickyRatchetPayoff> (boost::dynamic_pointer_cast<QuantLib::DoubleStickyRatchetPayoff> (*_ppRatchetMaxPayoff));
}
#endif

Cephei::QL::Instruments::CRatchetMaxPayoff::~CRatchetMaxPayoff ()
{
    if (_ppRatchetMaxPayoff != NULL)
    {
	    delete _ppRatchetMaxPayoff;
        _ppRatchetMaxPayoff = NULL;
    }
}
Cephei::QL::Instruments::CRatchetMaxPayoff::!CRatchetMaxPayoff ()
{
    if (_ppRatchetMaxPayoff != NULL)
    {
	    delete _ppRatchetMaxPayoff;
    }
}
QuantLib::RatchetMaxPayoff& Cephei::QL::Instruments::CRatchetMaxPayoff::GetReference ()
{
    if (_ppRatchetMaxPayoff == NULL) throw gcnew NativeNullException ();
	return **_ppRatchetMaxPayoff;
}
boost::shared_ptr<QuantLib::RatchetMaxPayoff>& Cephei::QL::Instruments::CRatchetMaxPayoff::GetShared ()
{
    if (_ppRatchetMaxPayoff == NULL) throw gcnew NativeNullException ();
	return *_ppRatchetMaxPayoff;
}
QuantLib::RatchetMaxPayoff* Cephei::QL::Instruments::CRatchetMaxPayoff::GetPointer ()
{
    if (_ppRatchetMaxPayoff == NULL) throw gcnew NativeNullException ();
	return &**_ppRatchetMaxPayoff;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::RatchetMaxPayoff>& Cephei::QL::Instruments::CRatchetMaxPayoff::GetHandle ()
{
	if (_phRatchetMaxPayoff == NULL)
	{
		_phRatchetMaxPayoff = new Handle<QuantLib::RatchetMaxPayoff> (*_ppRatchetMaxPayoff);
	}
	return *_phRatchetMaxPayoff;
}
#endif
bool Cephei::QL::Instruments::CRatchetMaxPayoff::HasNative () 
{
	return (_ppRatchetMaxPayoff != NULL);
}

String^ Cephei::QL::Instruments::CRatchetMaxPayoff::Name::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppRatchetMaxPayoff)->name ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::IRatchetMaxPayoff^ Cephei::QL::Instruments::CRatchetMaxPayoff_Factory::Create (Double gearing1, Double gearing2, Double gearing3, Double spread1, Double spread2, Double spread3, Double initialValue1, Double initialValue2, Double accrualFactor)
{
    return gcnew CRatchetMaxPayoff ( gearing1,  gearing2,  gearing3,  spread1,  spread2,  spread3,  initialValue1,  initialValue2,  accrualFactor);
}
